package ut.Title_1_10;

import java.util.ArrayList;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import pojo.ListNode;
import solution.Title_1_10.AddTwoNumbers;

/**
 * @author FreyaZ
 * @version 2018-01-01
 */
public class AddTwoNumbersUT {
    @Test
    public void test() {
        List<TwoNumbersTuple> twoNumbersTupleList = new ArrayList<>();
        twoNumbersTupleList.add(new TwoNumbersTuple(new int[]{2, 4, 3}, new int[]{5, 6, 4}, "[7, 0, 8]"));
        twoNumbersTupleList.add(new TwoNumbersTuple(new int[]{3}, new int[]{7, 9, 9}, "[0, 0, 0, 1]"));
        twoNumbersTupleList.add(new TwoNumbersTuple(new int[]{0}, new int[]{0, 0, 0, 1}, "[0, 0, 0, 1]"));

        for (TwoNumbersTuple tuple : twoNumbersTupleList) {
            ListNode l1 = new ListNode(tuple.getL1());
            ListNode l2 = new ListNode(tuple.getL2());
            ListNode resultNode = AddTwoNumbers.addTwoNumbers(l1, l2);
            System.out.println(l1.toString() + " + " + l2.toString() + " = " + resultNode + " : " + tuple.getResult());
            Assert.assertEquals(tuple.getResult(), resultNode.toString());
        }
    }

    class TwoNumbersTuple {
        private int[] l1;
        private int[] l2;
        private String result;

        TwoNumbersTuple(int[] l1, int[] l2, String result) {
            this.l1 = l1;
            this.l2 = l2;
            this.result = result;
        }

        public int[] getL1() {
            return l1;
        }

        public int[] getL2() {
            return l2;
        }

        public String getResult() {
            return result;
        }
    }
}
